<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<script src='/Public/jquery.min.js'></script>
	<script src='/Public/foundation/js/foundation.min.js'></script>
	<link rel="stylesheet" href="/Public/foundation/css/foundation.min.css">
</head>
<body>
<div class="small-2 columns">
<ul class="side-nav">
 <?php if(is_array($nav)): $i = 0; $__LIST__ = $nav;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><li><a href="<?php echo U($vo['url']);?>" target='<?php echo ($vo["target"]?"_blank":null); ?>'><?php echo ($vo["mname"]); ?></a></li><?php endforeach; endif; else: echo "" ;endif; ?>
    </ul>
</div>
<div class="small-10 columns">

<form action="?" method='get'>
    <fieldset>
        
            <?php if(is_array($vvvo)): $i = 0; $__LIST__ = $vvvo;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$list): $mod = ($i % 2 );++$i;?><input type="checkbox" name='field' value="<?php echo ($list["field"]); ?>"><?php echo ($list["field"]); endforeach; endif; else: echo "" ;endif; ?>
            <input type="submit" value='搜索'>
       
    </fieldset>
</form>
<table id='Tbl'>
<thead>
	<tr>
		<th><input type="checkbox" onclick="selectAll(this)" value='全选'></th>
		<th>编号</th>
		<th>关键字</th>
		<th>值</th>
		<th>描述</th>
		<th>锁定</th>
		<th>操作</th>
	</tr>
	</thead>
	<tbody>
	<?php if(is_array($dict)): $i = 0; $__LIST__ = $dict;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><tr id="row_<?php echo ($vo["dict_id"]); ?>">
			<td><input type="checkbox" class='select' value='<?php echo ($vo["dict_id"]); ?>' ></td>
			<td><?php echo ($vo["dict_id"]); ?></td>
			<td><input name="field" class="clss" disabled type="text" value="<?php echo ($vo["field"]); ?>"></td>
			<td><input name="val" class="clss" disabled type="text" value="<?php echo ($vo["val"]); ?>"></td>
			<td><input name="desc" class="clss" disabled style="width:4em;" type="text" value="<?php echo ($vo["desc"]); ?>"></td>
                
			<td>
			
             <div class="switch tiny">
              <input onclick="lock(this)" value="<?php echo ($vo["dict_id"]); ?>" id="lock_<?php echo ($vo["dict_id"]); ?>" type="checkbox"  <?php echo ($vo['lock']?'checked':''); ?>>
                <label for="lock_<?php echo ($vo["dict_id"]); ?>"></label>
                </div>   
			</td>  
			<td>
			<button type="button" onclick='edit("<?php echo ($vo["dict_id"]); ?>")' class='edit'>编辑</button>
			<button style='display:none' onclick='save("<?php echo ($vo["dict_id"]); ?>")' type="button" class="save">保存</button>
			</td>
		</tr><?php endforeach; endif; else: echo "" ;endif; ?>
	</tbody>
</table>
<input type="button" class="button" onclick="moreDel()" value='删除(批量)'>
<input type="button" class="button" onclick="unSelect()" value='反选'>
<input type="button" class="button" onclick="add()" value='添加'>
<input type="button" class="button" onclick="cancel()" value='取消'>
<script>
        function selectAll(obj) {
            $('#Tbl tbody .select').prop('checked',$(obj).prop('checked'));
        }
        function unSelect() {
            $('#Tbl tbody .select').map(function(){
                $(this).prop('checked',!$(this).prop('checked'));
            });
        }
        function moreDel() {
            if(!confirm('确定删除吗?')){
                return;
            }
            var ids = $('#Tbl tbody .select:checked').map(function () {
                $(this).parent().parent().remove();
                return $(this).val();
            });
            ids  = ids.get().join();
            $.post('<?php echo U("doDelDict");?>',{ids:ids},function (data) {
                if(data.error ==0)alert(data.msg);
            });
        }
        function lock(obj) {
            var id = $(obj).val();
            var lockval = $(obj).prop('checked')?1:0;
            $.post('<?php echo U("doEditDict");?>',{dict_id:id,lock:lockval});
        }

        
        
        function edit(id) {
            $('#row_'+id+' .clss').prop('disabled',false);
            $('#row_'+id+' .edit').hide();
            $('#row_'+id+' .save').show();
        }

        function save(id) {
            $('#row_'+id+' .clss').prop('disabled',true);
            $('#row_'+id+' .edit').show();
            $('#row_'+id+' .save').hide();

            var data = {
                dict_id:id,
                field:$('#row_'+id+' [name=field]').val(),
                val:  $('#row_'+id+' [name=val]').val(),
                desc :  $('#row_'+id+' [name=desc]').val(),
            }

            $.post('<?php echo U("doEditDict");?>',data,function (data) {
                if(data.error==0){
                    alert(data.msg);
                }
            });

        }
        function add(){
            $.get("<?php echo U('lastId');?>", '',
            function(id){
               var id= parseInt(id)+1;

                var html ="     <tr id=\'row_"+id+"\'>"+
    "           <td><input type=\'checkbox\' class=\'select\' value=\'\' ></td>"+
    "           <td>"+id+"</td>"+
    "           <td><input name=\'field\' class=\'clss\' disabled type=\'text\' value=\'\'></td>"+
    "           <td><input name=\'val\' class=\'clss\' disabled type=\'text\' value=\'\'></td>"+
    "           <td><input name=\'desc\' class=\'clss\' disabled style=\'width:4em;\' type=\'text\' value=\'\'></td>"+
    "                "+
    "           <td>"+
    "           "+
    "             <div class=\'switch tiny\'>"+
    "              <input onclick=\'lock(this)\' value=\'>\' id=\'lock_>\' type=\'checkbox\'  <?php echo ($vo['lock']?'checked':''); ?>>"+
    "                <label for=\'lock_"+id+"\'></label>"+
    "                </div>   "+
    "           </td>  "+
    "           <td>"+
    "           <button type=\'button\' onclick=\'edit("+id+")\' class=\'edit\'>编辑</button>"+
    "           <button style=\'display:none\' onclick=\'save("+id+")\' type=\'button\' class=\'save\'>保存</button>"+
    "           </td>"+
    "       </tr>";

            $('tbody').append(html);
            
            });
        }

        


</script>

</div>

</body>
</html>